package com.csrcb.service;

import com.csrcb.tools.EmailUtil;
import com.csrcb.tools.NetEasyEmailOnject;
import com.csrcb.tools.QqEmailObject;

import javax.mail.Message;
import javax.mail.MessagingException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Classname EmailSendService
 * @Description 邮箱发送
 * @Date 2020/12/18 15:26
 * @Created by gangye
 */
public class EmailSendService {

    public static void sendQqEmailforWeChatFail(boolean flag,String ems1){
        QqEmailObject qqEmailObject = new QqEmailObject();
        qqEmailObject.setTitle("微信发送失败请求");
        qqEmailObject.setSendAddress("xxxxxxxx@qq.com");
        qqEmailObject.setAcceptAddress("xxxxxxxx@qq.com");
        String sendMessage;
        if (flag){
            sendMessage = "证书的信息已变更，及时查看\n"
                    + "时间:"+new SimpleDateFormat("yyyy-MM-dd").format(new Date())+"\n"
                    + "EMS单号:"+ems1;
        }else{
            sendMessage = "微信公众号发送失败\n" +
                    "时间:"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        }
        qqEmailObject.setEmailContent(sendMessage);
        qqEmailObject.setToken("xxxxxxxx");
        try {
            EmailUtil.sendQQEmail(qqEmailObject);
        } catch (MessagingException e) {
            e.printStackTrace();
        }
        //程序退出
        System.exit(0);
    }

    public static void sendNetEasyEmailforWeChatFail(String sendMessage){
        NetEasyEmailOnject netEasyEmailOnject = new NetEasyEmailOnject();
        netEasyEmailOnject.setTitle("微信发送失败请求");
        netEasyEmailOnject.setSendAddress("xxxxxx@163.com");
        String[] acceptAddress = {"xxxxx@qq.com","xxxxx@163.com"};
        netEasyEmailOnject.setAcceptsAddress(acceptAddress);
        netEasyEmailOnject.setNetEastContent(sendMessage);
        netEasyEmailOnject.setToken("xxxxxxxxxxx");
        netEasyEmailOnject.setUser("xxxxxx@163.com");
        EmailUtil.sendNetEasyEmail(netEasyEmailOnject);
        System.exit(0);
    }
}
